import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) throws Exception {

        /*
        select * from jdbc_practice;
        select * from jdbc_practice where name like '%o%' ;
        insert into jdbc_practice(name,id) values('zhangsan','3');
        update jdbc_practice set name='lisi' where id='3';
        delete from jdbc_practice where id='3';
         */


        //加载配置文件
        Properties prop=new Properties();
        prop.load(new FileInputStream("src/druid.properties"));
        //获取链接池对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);

        //获取数据库链接
        Connection conn = dataSource.getConnection();

        String sql="select * from jdbc_practice;";

        //获取ps对象
        PreparedStatement ps=conn.prepareStatement(sql);

        //执行sql
        ResultSet rs = ps.executeQuery();

        while (rs.next()){
            System.out.println("id:"+rs.getString("id")+"   name:"+rs.getString("name"));
        }

        rs.close();
        ps.close();

    }
}